package com.zzyl.serve.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.dto.NursingPlanDto;
import com.zzyl.serve.vo.vo.NursingPlanVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.NursingPlan;
import com.zzyl.serve.service.INursingPlanService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理计划Controller
 *
 * @author fzk
 * @date 2025-07-20
 */
@RestController
@RequestMapping("/serve/plan")
@Api(tags = "护理计划管理接口") // 为整个Controller添加标签，用于接口分类
public class NursingPlanController extends BaseController {
    @Autowired
    private INursingPlanService nursingPlanService;

    /**
     * 查询护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:list')")
    @GetMapping("/list")
    @ApiOperation("查询护理计划列表")
    public TableDataInfo list(
            @ApiParam(name = "nursingPlan", value = "护理计划查询条件（可选）", required = false)
            NursingPlan nursingPlan) {
        startPage();
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        return getDataTable(list);
    }

    /**
     * 导出护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:export')")
    @Log(title = "护理计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出护理计划数据到Excel")
    public void export(
            @ApiParam(name = "response", value = "HTTP响应对象（用于输出Excel文件）", required = true)
            HttpServletResponse response,
            @ApiParam(name = "nursingPlan", value = "导出条件（可选）", required = false)
            NursingPlan nursingPlan) {
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        ExcelUtil<NursingPlan> util = new ExcelUtil<NursingPlan>(NursingPlan.class);
        util.exportExcel(response, list, "护理计划数据");
    }

    /**
     * 获取护理计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理计划详细信息")
    public R<NursingPlanVo> getInfo(
            @ApiParam(name = "id", value = "护理计划的唯一标识", required = true)
            @PathVariable("id") Integer id) {
        return R.ok(nursingPlanService.selectNursingPlanById(id));
    }

    /**
     * 新增护理计划
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:add')")
    @Log(title = "护理计划", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增护理计划")
    public AjaxResult add(
            @ApiParam(name = "nursingPlan", value = "要新增的护理计划对象", required = true)
            @RequestBody NursingPlanDto nursingPlanDto) {
        int row = nursingPlanService.insertNursingPlan(nursingPlanDto);
        return toAjax(row);
    }

    /**
     * 修改护理计划
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:edit')")
    @Log(title = "护理计划", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新护理计划信息")
    public AjaxResult update(
            @ApiParam(name = "nursingPlan", value = "要更新的护理计划对象", required = true)
            @RequestBody NursingPlanDto nursingPlanDto) {
        return toAjax(nursingPlanService.updateNursingPlan(nursingPlanDto));
    }

    /**
     * 删除护理计划
     */
    @PreAuthorize("@ss.hasPermi('serve:plan:remove')")
    @Log(title = "护理计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public AjaxResult remove(
            @ApiParam(name = "ids", value = "要删除的护理计划ID数组", required = true)
            @PathVariable Integer id) {
        return toAjax(nursingPlanService.deleteNursingPlanById(id));
    }

    /**
     * 查询护理项目列表
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理计划")
    public AjaxResult findAll() {
        List<NursingPlanVo> list = nursingPlanService.findAll();
        return success(list);
    }
}
